<?php
use Yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\widgets\LinkPager;
$this->title = '运营管理';
?>

 <div class="container">
    <div class="row">
       <?php echo $this->render('_leftnav'); ?>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">资讯管理</h1>
            <div class="pull-right">

                <a class="btn btn-success btn-sm" href="<?= Url::to(['operate/artadd']);?>">添加资讯</a>

                                                
            </div>
          </div>
          
          
       
<?php $form = ActiveForm::begin([
			'options'=>['class'=>'well well-sm form-inline'],
			'action' => ['operate/artsearch'],
			'method'=>'post',
	]); ?>
	<div class="form-group">
	
		<select class="form-control" name="artlable_name" >
		 <option value="">--选择标签--</option>
		   	<?php foreach ($db as $key => $val) {?>
		   		<?php if($label_name==$val['artlable_name']){?>
		   			<option value="<?php echo $val['artlable_name']?>" selected><?php echo $val['artlable_name']?></option>
		   		<?php }else{?>
		   			<option value="<?php echo $val['artlable_name']?>"><?php echo $val['artlable_name']?></option>	
		   		<?php }?>
			<?php }?>
		</select>
		
		
	</div>
	<div class="form-group">
		<input class="form-control" name="keywords" placeholder="标题关键词" value="<?php if(!empty($keywords)){echo $keywords;}?>" type="text">
	</div>
	<div class="form-group">
		<select class="form-control" name="is_show">
		<option value="" selected="selected">--发布状态--</option>
			<option value="1">已发布</option>
		  	<option value="0">未发布</option>
		</select>
	</div>
	<button class="btn btn-primary" type="submit">搜索</button>

<?php ActiveForm::end(); ?>

<div id="aticle-table-container">

<table class="table table-hover table-striped" id="article-table">
	<thead>
		<tr>
			<th width="10%"><input data-role="batch-select" type="checkbox"> ID</th>
			<th width="20%">资讯标题</th>
			<th width="15%">所属标签</th>
			<th width="18%">更新时间</th>
			<th width="10%">状态</th>
			<th width="15%">操作</th>
		</tr>
	</thead>
	<tbody>
			<?php foreach($artist as $key =>$val){?>
								  			  <tr id="article-<?php echo $val['article_id']?>">
	<td><input value="{$val['article_id']}" data-role="batch-item" type="checkbox"> <?php echo $val['article_id']?></td>
	<td>
			<span class="text-muted">
				<?php
					$str = $val['article_title'];
					if(strlen($str)<30){
                        echo $str;
                    }else{
						$num = mb_substr($str,0,33,'utf-8');
						$rrr  = str_replace($str,$num."...",$str);
						echo $rrr;
					}	 
				?>
			</span>
	</td>
	<td>
			<span class="text-muted"><?php echo $val['artlable_name']?></span>
			</td>
	<td><?php echo date('Y-m-d H:i:s',$val['article_updtime'])?></td>
	<?php if($val['is_show']==1){?>
	<td><span class="text-success">已发布</span></td>
	<?php }else{?>
	<td><span><font color='red'>未发布</font></span></td>
	<?php }?>
	<td>
		<div class="btn-group">
		  <a href="<?= Url::to(['operate/artedit']);?>&article_id=<?php echo $val['article_id']?>" class="btn btn-default btn-sm "  ><i class="glyphicon glyphicon-edit"></i> 编辑</a>
		  <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
		    <span class="caret"></span>
		  </a>
		  <ul class="dropdown-menu">
		  								<?php if($val['is_show']==1){?>
		  		     				    <li><a href="javascript:" data-role="unpublish-item" name="<?php echo $val['article_id']?>" m="<?php echo $val['is_show']?>" class="unpublish">取消发布</a></li>
		  		     				    <?php }else{?>
		  		     				    <li><a href="javascript:" data-role="unpublish-item" name="<?php echo $val['article_id']?>" m="<?php echo $val['is_show']?>" class="unpublish">发布</a></li>
		  		     				    <?php }?>
		    		    			    <li><a href="javascript:" data-role="trash-item" class="artdel" name="<?php echo $val['article_id']?>">删除</a></li>
		    		    		  </ul>
		</div>
	</td>
</tr>
	<?php }?>
                    </tbody>
	</table>
  <!--<div>
    <label class="checkbox-inline"><input data-role="batch-select" type="checkbox"> 全选</label>
    <button class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="资讯" data-url="/admin/article/delete/article_id/">删除</button>
  </div>-->
  </div>
<?php echo LinkPager::widget([
				'pagination' => $pages,
				'prevPageLabel'=>'上一页',
				'nextPageLabel'=>'下一页',
			]);?>
  

        </div>

          </div>
    <div id="artedit" class="modal fade"></div>
  </div>
 	
 </div>

 <script>
 
 	//资讯删除
 	$(".artdel").click(function(){
 		var art_id = $(this).attr('name');
 		$.ajax({
   			type: "POST",
   			url: "<?= Url::to(['operate/artdel']);?>",
   			data: "art_id="+art_id,
   			success:function(msg){	
   				var msg=JSON.parse(msg);
   				if(msg.code==1){
   					alert('删除成功');
   					history.go(0);
   				}else{
   					alert('删除失败');
   					history.go(0);
   				}
   			}
		});
 	})
 	//资讯修改
 	$(".unpublish").click(function(){
 		var art_id = $(this).attr('name');
 		var is_show = $(this).attr('m');
 		$.ajax({
   			type: "POST",
   			url: "<?= Url::to(['operate/unpublish']);?>",
   			data: "art_id="+art_id+"&is_show="+is_show,
   			success:function(msg){
   				var msg=JSON.parse(msg);
   				if(msg.code==1){
   					alert('ok');
   					history.go(0);
   				}else{
   					alert('更改失败');
   					history.go(0);
   				}
   			}
		});
 	})
 </script>